home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / libg_261.zip / libg_261 / libg++ / etc / lf / Dirent.h < prev    next >
C/C++ Source or Header  |  1992-05-29  |  2KB  |  94 lines

  1. /* Define a portable UNIX directory-entry manipulation interface. 
  2.  
  3.    This code is heavily based upon Doug Gwyn's public domain directory-access
  4.    routines.  Hacked into C++ conformance by Doug Schmidt (schmidt@ics.uci.edu). */
  5.  
  6. #include <builtin.h>
  7. #include <sys/types.h>
  8. #include <sys/stat.h>
  9. #include <dirent.h>
  10.  
  11. #ifdef rewinddir
  12. #undef rewinddir
  13. #endif
  14.  
  15. class Dirent
  16. {
  17. private:
  18.   DIR *dirp;
  19.  
  20. public:
  21.                  Dirent (char *dirname);
  22.                 ~Dirent (void);
  23.   struct dirent *readdir (void);
  24.   void           opendir (char *filename);
  25.   void           closedir (void);
  26.   long           telldir (void);
  27.   void           seekdir (long loc);
  28.   void           rewinddir (void);
  29. };
  30.  
  31. // error handlers
  32.  
  33. extern void  verbose_Dirent_error_handler(const char*);
  34. extern void  quiet_Dirent_error_handler(const char*);
  35. extern void  fatal_Dirent_error_handler(const char*);
  36. extern one_arg_error_handler_t Dirent_error_handler;
  37. extern one_arg_error_handler_t set_Dirent_error_handler(one_arg_error_handler_t);
  38.  
  39. // OPTIMIZE
  40.  
  41. #ifdef __OPTIMIZE__
  42.  
  43. inline 
  44. Dirent::Dirent (char *dirname) 
  45. {
  46.   if ((dirp = ::opendir (dirname)) == 0)
  47.     (*Dirent_error_handler) ("Dirent::Dirent");
  48. }
  49.  
  50. inline 
  51. Dirent::~Dirent (void)
  52. {
  53.   ::closedir (dirp);
  54. }
  55.  
  56. inline void
  57. Dirent::opendir (char *dirname) 
  58. {
  59.   if ((dirp = ::opendir (dirname)) == 0)
  60.     (*Dirent_error_handler) ("Dirent::Dirent");
  61. }
  62.  
  63. inline struct dirent *
  64. Dirent::readdir (void)
  65. {
  66.   return ::readdir (dirp);
  67. }
  68.  
  69. inline void
  70. Dirent::closedir (void)
  71. {
  72.  ::closedir (dirp);
  73. }
  74.  
  75. inline void
  76. Dirent::rewinddir (void)
  77. {
  78.   ::seekdir (dirp, long (0));
  79. }
  80.  
  81. inline void
  82. Dirent::seekdir (long loc)
  83. {
  84.   ::seekdir (dirp, loc);
  85. }
  86.  
  87. inline long
  88. Dirent::telldir (void)
  89. {
  90.   return ::telldir (dirp);
  91. }
  92.  
  93. #endif // __OPTIMIZE__
  94.